﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HotelMatchUtility.Match;
using HotelMatchUtility.Utility;
using HotelMatchUtility.Comparer;
using HotelMatchUtility.Entity;
using HotelMatchUtility.Data;

namespace HotelMatchUtility.Facade
{
    public class MatchFacade
    {
        public static string MatchOutName;

        public static int leftNumber;

        public static int rightNumber;

        //public static void StartMatch20131129()
        //{
        //    //Round thisRound = new Round("Booking2.5W Agoda2W酒店上线");

        //    List<int> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\BookingId.txt");
        //    List<int> AgodaHotelList = Y_FileReader.ReadIdFromFile(@"C:\AgodaId.txt");

        //    ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
        //    ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
        //    ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
        //    ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
        //    ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

        //    //5Km 酒店名称65%以上相似
        //    ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
        //    //5Km 地址65%以上相似
        //    ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

        //    List<CountryEntity> CountryList = CountryData.GetCountryList();

        //    foreach (var country in CountryList)
        //    {
        //        leftNumber = 0;
        //        rightNumber = 0;
        //        MatchOutName = "初始化数据";

        //        List<HotelEntity> OtherList = OtherData.GetData(country.CountryId, new List<int>() { 32, 33 });
        //        List<HotelEntity> BookingList = BookingData.GetData(country.CountryId, BookingHotelList);
        //        List<HotelEntity> AgodaList = AgodaData.GetData(country.CountryId, AgodaHotelList);

        //        //1111-------------------------------------------------------------------------------//
        //        string MatchName = country.CountryName + "_BtoA_精确匹配";
        //        MatchOutName = MatchName;
        //        leftNumber = BookingList.Count;
        //        rightNumber = AgodaList.Count;

        //        MatchEntity match_BtoA_Acc = new MatchEntity(MatchName);
        //        match_BtoA_Acc.LeftTargetEntityList = BookingList;
        //        match_BtoA_Acc.RightToCompareEntityList = AgodaList;
        //        match_BtoA_Acc.ResultList = new List<HotelEntity>();
        //        match_BtoA_Acc.ExactConditionList = new List<ICompareCondition>();

        //        match_BtoA_Acc.ExactConditionList.Add(NameAddressAccComparer);
        //        match_BtoA_Acc.ExactConditionList.Add(GeoComparer1);
        //        match_BtoA_Acc.ExactConditionList.Add(GeoComparer2);
        //        match_BtoA_Acc.ExactConditionList.Add(TelephoneComparer);
        //        match_BtoA_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

        //        match_BtoA_Acc.DoMatch();
        //        Y_FileOutputer.DoOutput(match_BtoA_Acc.ResultList, match_BtoA_Acc.GetMatchName());
        //        //2222------------------------------------------------------------------------------//
        //        MatchName = country.CountryName + "_BA精确toOther_精确和相似匹配";
        //        MatchOutName = MatchName;
        //        leftNumber = match_BtoA_Acc.ResultList.Count;
        //        rightNumber = OtherList.Count;

        //        MatchEntity match_ABtoOther_Acc = new MatchEntity(MatchName);
        //        match_ABtoOther_Acc.LeftTargetEntityList = match_BtoA_Acc.ResultList;
        //        match_ABtoOther_Acc.RightToCompareEntityList = OtherList;
        //        match_ABtoOther_Acc.ResultList = new List<HotelEntity>();
        //        match_ABtoOther_Acc.ExactConditionList = new List<ICompareCondition>();
        //        match_ABtoOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
        //        match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer1);
        //        match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer2);
        //        match_ABtoOther_Acc.ExactConditionList.Add(TelephoneComparer);
        //        match_ABtoOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

        //        match_ABtoOther_Acc.SimilarConditionList = new List<ICompareCondition>();
        //        match_ABtoOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
        //        match_ABtoOther_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);

        //        match_ABtoOther_Acc.DoMatch();
        //        Y_FileOutputer.DoOutput(match_ABtoOther_Acc.ResultList, match_ABtoOther_Acc.GetMatchName());


        //        ////3333-----------------------------------------------------------------------------//
        //        //MatchName = country.CountryName + "_BA精确toOhter_相似匹配";
        //        //MatchEntity match_ABSimToOther_Acc = new MatchEntity(MatchName);
        //        ////去掉第一步的结果集中的酒店
        //        //foreach (var baToOtherAccEntity in match_ABtoOther_Acc.ResultList)
        //        //{
        //        //    var abToOtherAcc = match_BtoA_Acc.ResultList.Where(btoa => btoa.Hotel == baToOtherAccEntity.Hotel).First();
        //        //    match_BtoA_Acc.ResultList.Remove(abToOtherAcc);
        //        //    //去掉OtherList在第二步中匹上的酒店 (因为已经置过flag所以匹配上的match时不会被比较了
        //        //    //Do nothing
        //        //}

        //        //match_ABSimToOther_Acc.LeftTargetEntityList = match_BtoA_Acc.ResultList;
        //        //match_ABSimToOther_Acc.RightToCompareEntityList = OtherList;

        //        //MatchOutName = MatchName;
        //        //leftNumber = match_BtoA_Acc.ResultList.Count;
        //        //rightNumber = OtherList.Count;
        //        //match_ABSimToOther_Acc.ResultList = new List<HotelEntity>();

        //        //match_ABSimToOther_Acc.ExactConditionList = new List<ICompareCondition>();
        //        //match_ABSimToOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
        //        //match_ABSimToOther_Acc.ExactConditionList.Add(GeoComparer1);
        //        //match_ABSimToOther_Acc.ExactConditionList.Add(GeoComparer2);
        //        //match_ABSimToOther_Acc.ExactConditionList.Add(TelephoneComparer);
        //        //match_ABSimToOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

        //        //match_ABSimToOther_Acc.SimilarConditionList = new List<ICompareCondition>();
        //        //match_ABSimToOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);

        //        //match_ABSimToOther_Acc.DoMatch();
        //        //Y_FileOutputer.DoOutput(match_ABSimToOther_Acc.ResultList, match_ABSimToOther_Acc.GetMatchName());
        //        //4444-----------------------------------------------------------------------------//
        //        MatchName = country.CountryName + "_BA相似toOhter_相似匹配";
        //        MatchEntity match_ABSimToOther_Sim = new MatchEntity(MatchName);

        //        //去掉 BA精确匹配结果，其他进入相似匹配
        //        foreach (var result in match_BtoA_Acc.ResultList)
        //        {
        //            var bEntity = BookingList.Where(bentity => bentity.Hotel == result.Hotel).First();
        //            foreach (var exactEntity in result.ExactMatchResult)
        //            {
        //                HotelEntity toRemove = null ;
        //                foreach (var aEntity in AgodaList)
        //                {
        //                    if (aEntity.Hotel == exactEntity.Hotel)
        //                    {
        //                        toRemove = aEntity;
        //                        break;
        //                    }
        //                }
        //                if(toRemove != null)
        //                    AgodaList.Remove(toRemove);
        //            }
        //            BookingList.Remove(bEntity);
        //        }
        //        //A and B 啥都没匹上的酒店集合
        //        BookingList.AddRange(AgodaList);

        //        match_ABSimToOther_Sim.LeftTargetEntityList = BookingList;
        //        match_ABSimToOther_Sim.RightToCompareEntityList = OtherList;
        //        MatchOutName = MatchName;
        //        leftNumber = BookingList.Count;
        //        rightNumber = OtherList.Count;

        //        match_ABSimToOther_Sim.ResultList = new List<HotelEntity>();

        //        match_ABSimToOther_Sim.ExactConditionList = new List<ICompareCondition>();

        //        NameAddressAccComparer.SetTargetIsContinue(false);
        //        GeoComparer1.SetTargetIsContinue(false);
        //        GeoComparer2.SetTargetIsContinue(false);
        //        TelephoneComparer.SetTargetIsContinue(false);
        //        NameAddressHighSimComparer.SetTargetIsContinue(false);

        //        match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressAccComparer);
        //        match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer1);
        //        match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer2);
        //        match_ABSimToOther_Sim.ExactConditionList.Add(TelephoneComparer);
        //        match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressHighSimComparer);

        //        match_ABSimToOther_Sim.SimilarConditionList = new List<ICompareCondition>();
        //        match_ABSimToOther_Sim.SimilarConditionList.Add(SimNameAndGeoComparer);
        //        match_ABSimToOther_Sim.SimilarConditionList.Add(SimAddressAndGeoComparer);
        //        match_ABSimToOther_Sim.DoMatch();
        //        Y_FileOutputer.DoOutput(match_ABSimToOther_Sim.ResultList, match_ABSimToOther_Sim.GetMatchName());

        //        foreach (var result in match_ABSimToOther_Sim.ResultList)
        //        {
        //            var bEntity = BookingList.Where(bentity => bentity.Hotel == result.Hotel).First();
                   
        //            BookingList.Remove(bEntity);
        //        }
        //        Y_FileOutputer.DoOutput(BookingList, country.CountryName + "_未匹配上BA酒店");
        //    }
        //}

        public static void StartMatch20131217()
        {
            //List<int> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\BookingId.txt");
            //List<int> AgodaHotelList = Y_FileReader.ReadIdFromFile(@"C:\AgodaId.txt");

            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            List<CountryEntity> CountryList = CountryData.GetCountryList();
            CountryList = CountryList.Where(p => p.CountryId == 2).ToList();

            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";

                List<HotelEntity> OtherList = OtherData.GetData(country.CountryId, new List<int>() { 32, 33 });
                List<HotelEntity> BookingList = BookingData.GetDataByCityId(country.CountryId, 1393, null);
                List<HotelEntity> AgodaList = AgodaData.GetDataByCityId(country.CountryId,1393, null);

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_BtoA_精确匹配";
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = AgodaList.Count;

                MatchEntity match_BtoA_Acc = new MatchEntity(MatchName);
                match_BtoA_Acc.LeftTargetEntityList = BookingList;
                match_BtoA_Acc.RightToCompareEntityList = AgodaList;
                match_BtoA_Acc.ResultList = new List<HotelEntity>();
                match_BtoA_Acc.ExactConditionList = new List<ICompareCondition>();

                match_BtoA_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer1);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer2);
                match_BtoA_Acc.ExactConditionList.Add(TelephoneComparer);
                match_BtoA_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_BtoA_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_BtoA_Acc.ResultList, match_BtoA_Acc.GetMatchName());
                //2222------------------------------------------------------------------------------//
                MatchName = country.CountryName + "_BA精确toOther_精确和相似匹配";
                MatchOutName = MatchName;
                leftNumber = match_BtoA_Acc.ResultList.Count;
                rightNumber = OtherList.Count;

                MatchEntity match_ABtoOther_Acc = new MatchEntity(MatchName);
                match_ABtoOther_Acc.LeftTargetEntityList = match_BtoA_Acc.ResultList;
                match_ABtoOther_Acc.RightToCompareEntityList = OtherList;
                match_ABtoOther_Acc.ResultList = new List<HotelEntity>();
                match_ABtoOther_Acc.ExactConditionList = new List<ICompareCondition>();
                match_ABtoOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer1);
                match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer2);
                match_ABtoOther_Acc.ExactConditionList.Add(TelephoneComparer);
                match_ABtoOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_ABtoOther_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_ABtoOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_ABtoOther_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);

                match_ABtoOther_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_ABtoOther_Acc.ResultList, match_ABtoOther_Acc.GetMatchName());


                //4444-----------------------------------------------------------------------------//
                MatchName = country.CountryName + "_BA相似toOhter_相似匹配";
                MatchEntity match_ABSimToOther_Sim = new MatchEntity(MatchName);

                //去掉 BA精确匹配结果，其他进入相似匹配
                foreach (var result in match_BtoA_Acc.ResultList)
                {
                    var bEntity = BookingList.Where(bentity => bentity.Hotel == result.Hotel).First();
                    foreach (var exactEntity in result.ExactMatchResult)
                    {
                        HotelEntity toRemove = null;
                        foreach (var aEntity in AgodaList)
                        {
                            if (aEntity.Hotel == exactEntity.Hotel)
                            {
                                toRemove = aEntity;
                                break;
                            }
                        }
                        if (toRemove != null)
                            AgodaList.Remove(toRemove);
                    }
                    BookingList.Remove(bEntity);
                }
                //A and B 啥都没匹上的酒店集合
                BookingList.AddRange(AgodaList);

                match_ABSimToOther_Sim.LeftTargetEntityList = BookingList;
                match_ABSimToOther_Sim.RightToCompareEntityList = OtherList;
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = OtherList.Count;

                match_ABSimToOther_Sim.ResultList = new List<HotelEntity>();

                match_ABSimToOther_Sim.ExactConditionList = new List<ICompareCondition>();

                NameAddressAccComparer.SetTargetIsContinue(false);
                GeoComparer1.SetTargetIsContinue(false);
                GeoComparer2.SetTargetIsContinue(false);
                TelephoneComparer.SetTargetIsContinue(false);
                NameAddressHighSimComparer.SetTargetIsContinue(false);

                match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressAccComparer);
                match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer1);
                match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer2);
                match_ABSimToOther_Sim.ExactConditionList.Add(TelephoneComparer);
                match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressHighSimComparer);

                match_ABSimToOther_Sim.SimilarConditionList = new List<ICompareCondition>();
                match_ABSimToOther_Sim.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_ABSimToOther_Sim.SimilarConditionList.Add(SimAddressAndGeoComparer);
                match_ABSimToOther_Sim.DoMatch();
                Y_FileOutputer.DoOutput(match_ABSimToOther_Sim.ResultList, match_ABSimToOther_Sim.GetMatchName());
            }
        }

        public static void StartMatch20131223()
        {
            //List<int> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\BookingId.txt");
            //List<int> AgodaHotelList = Y_FileReader.ReadIdFromFile(@"C:\AgodaId.txt");

            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            List<CountryEntity> CountryList = CountryData.GetCountryList();
            CountryList = CountryList.Where(p => p.CountryId != 2 && p.CountryId != 32 && p.CountryId != 50 && p.CountryId != 111
                && p.CountryId != 15 && p.CountryId != 28 && p.CountryId != 31 && p.CountryId != 66 && p.CountryId != 109)
                .ToList();

            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";

                List<HotelEntity> OtherList = OtherData.GetData(country.CountryId, new List<int>() { 32, 33 });
                List<HotelEntity> BookingList = BookingData.GetDataByCityId(country.CountryId, 0, null);
                List<HotelEntity> AgodaList = AgodaData.GetDataByCityId(country.CountryId, 0, null);

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_BtoA_精确匹配";
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = AgodaList.Count;

                MatchEntity match_BtoA_Acc = new MatchEntity(MatchName);
                match_BtoA_Acc.LeftTargetEntityList = BookingList;
                match_BtoA_Acc.RightToCompareEntityList = AgodaList;
                match_BtoA_Acc.ResultList = new List<HotelEntity>();
                match_BtoA_Acc.ExactConditionList = new List<ICompareCondition>();

                match_BtoA_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer1);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer2);
                match_BtoA_Acc.ExactConditionList.Add(TelephoneComparer);
                match_BtoA_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_BtoA_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_BtoA_Acc.ResultList, match_BtoA_Acc.GetMatchName());
                //2222------------------------------------------------------------------------------//
                MatchName = country.CountryName + "_BA精确toOther_精确和相似匹配";
                MatchOutName = MatchName;
                leftNumber = match_BtoA_Acc.ResultList.Count;
                rightNumber = OtherList.Count;

                MatchEntity match_ABtoOther_Acc = new MatchEntity(MatchName);
                match_ABtoOther_Acc.LeftTargetEntityList = match_BtoA_Acc.ResultList;
                match_ABtoOther_Acc.RightToCompareEntityList = OtherList;
                match_ABtoOther_Acc.ResultList = new List<HotelEntity>();
                match_ABtoOther_Acc.ExactConditionList = new List<ICompareCondition>();
                match_ABtoOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer1);
                match_ABtoOther_Acc.ExactConditionList.Add(GeoComparer2);
                match_ABtoOther_Acc.ExactConditionList.Add(TelephoneComparer);
                match_ABtoOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_ABtoOther_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_ABtoOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_ABtoOther_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);

                match_ABtoOther_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_ABtoOther_Acc.ResultList, match_ABtoOther_Acc.GetMatchName());


                //4444-----------------------------------------------------------------------------//
                MatchName = country.CountryName + "_BA相似toOhter_相似匹配";
                MatchEntity match_ABSimToOther_Sim = new MatchEntity(MatchName);

                //去掉 BA精确匹配结果，其他进入相似匹配
                foreach (var result in match_BtoA_Acc.ResultList)
                {
                    var bEntity = BookingList.Where(bentity => bentity.Hotel == result.Hotel).First();
                    foreach (var exactEntity in result.ExactMatchResult)
                    {
                        HotelEntity toRemove = null;
                        foreach (var aEntity in AgodaList)
                        {
                            if (aEntity.Hotel == exactEntity.Hotel)
                            {
                                toRemove = aEntity;
                                break;
                            }
                        }
                        if (toRemove != null)
                            AgodaList.Remove(toRemove);
                    }
                    BookingList.Remove(bEntity);
                }
                //A and B 啥都没匹上的酒店集合
                BookingList.AddRange(AgodaList);

                match_ABSimToOther_Sim.LeftTargetEntityList = BookingList;
                match_ABSimToOther_Sim.RightToCompareEntityList = OtherList;
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = OtherList.Count;

                match_ABSimToOther_Sim.ResultList = new List<HotelEntity>();

                match_ABSimToOther_Sim.ExactConditionList = new List<ICompareCondition>();

                NameAddressAccComparer.SetTargetIsContinue(false);
                GeoComparer1.SetTargetIsContinue(false);
                GeoComparer2.SetTargetIsContinue(false);
                TelephoneComparer.SetTargetIsContinue(false);
                NameAddressHighSimComparer.SetTargetIsContinue(false);

                match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressAccComparer);
                match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer1);
                match_ABSimToOther_Sim.ExactConditionList.Add(GeoComparer2);
                match_ABSimToOther_Sim.ExactConditionList.Add(TelephoneComparer);
                match_ABSimToOther_Sim.ExactConditionList.Add(NameAddressHighSimComparer);

                match_ABSimToOther_Sim.SimilarConditionList = new List<ICompareCondition>();
                match_ABSimToOther_Sim.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_ABSimToOther_Sim.SimilarConditionList.Add(SimAddressAndGeoComparer);
                match_ABSimToOther_Sim.DoMatch();
                Y_FileOutputer.DoOutput(match_ABSimToOther_Sim.ResultList, match_ABSimToOther_Sim.GetMatchName());

                foreach (var result in match_ABSimToOther_Sim.ResultList)
                {
                    var bEntity = BookingList.Where(bentity => bentity.Hotel == result.Hotel).First();

                    BookingList.Remove(bEntity);
                }
                Y_FileOutputer.DoOutput(BookingList, country.CountryName + "_未匹配上BA酒店");
            }
        }

        public static void StartMatch20140306()
        {
            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            NameAddressAccComparer.SetTargetIsContinue(false);
            GeoComparer1.SetTargetIsContinue(false);
            GeoComparer2.SetTargetIsContinue(false);
            TelephoneComparer.SetTargetIsContinue(false);
            NameAddressHighSimComparer.SetTargetIsContinue(false);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            List<CountryEntity> CountryList = CountryData.GetCountryListOrbitz();
            //CountryList.Add(new CountryEntity() { CountryCode = "CZ", CountryEnName = "Czech", CountryName="捷克", CountryId=162 });
            //CountryList.Add(new CountryEntity() { CountryCode = "KR", CountryEnName = "South Korea", CountryName = "韩国", CountryId = 42 });
            //CountryList.Add(new CountryEntity() { CountryCode = "LA", CountryEnName = "Laos", CountryName = "老挝", CountryId = 55 });
            //CountryList.Add(new CountryEntity() { CountryCode = "LY", CountryEnName = "Libya", CountryName = "利比亚", CountryId = 60 });
            //CountryList.Add(new CountryEntity() { CountryCode = "MD", CountryEnName = "Moldova", CountryName = "摩尔多瓦", CountryId = 182 });
            //CountryList.Add(new CountryEntity() { CountryCode = "MP", CountryEnName = "Northern Mariana Island", CountryName = "北马里亚纳群岛", CountryId = 262 });
            //CountryList.Add(new CountryEntity() { CountryCode = "PS", CountryEnName = "Palestine", CountryName = "巴勒斯坦", CountryId = 205 });
            //CountryList.Add(new CountryEntity() { CountryCode = "SK", CountryEnName = "Slovakia", CountryName = "斯洛伐克", CountryId = 247 });
            //CountryList.Add(new CountryEntity() { CountryCode = "TZ", CountryEnName = "Tanzania", CountryName = "坦桑尼亚", CountryId = 87 });
            //CountryList.Add(new CountryEntity() { CountryCode = "VG", CountryEnName = "BRITISH VIRGIN ISLAN", CountryName = "英属维尔京群岛", CountryId = 282 });
            //CountryList.Add(new CountryEntity() { CountryCode = "VI", CountryEnName = "U.S. VIRGIN ISLANDS", CountryName = "美属维尔京群岛", CountryId = 280 });
            //CountryList.Add(new CountryEntity() { CountryCode = "VN", CountryEnName = "Vietnam", CountryName = "越南", CountryId = 111 });
            //CountryList.Add(new CountryEntity() { CountryCode = "US", CountryEnName = "United States", CountryName = "美国", CountryId = 66 });

            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";

                List<HotelEntity> OtherList = OtherData.GetData(country.CountryId, new List<int>() { 32 });
                List<HotelEntity> BookingList = BookingData.GetDataByCityId(country.CountryId, 0, null);
                List<HotelEntity> OrbitzList = OrbitzData.GetData(country.CountryCode, null);
                OtherList.AddRange(OrbitzList);

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_BookingToOther_精确匹配";
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = OtherList.Count;

                MatchEntity match_OrbitzToOther_Acc = new MatchEntity(MatchName);
                match_OrbitzToOther_Acc.LeftTargetEntityList = BookingList;
                match_OrbitzToOther_Acc.RightToCompareEntityList = OtherList;
                match_OrbitzToOther_Acc.ResultList = new List<HotelEntity>();
                match_OrbitzToOther_Acc.ExactConditionList = new List<ICompareCondition>();

                match_OrbitzToOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_OrbitzToOther_Acc.ExactConditionList.Add(GeoComparer1);
                match_OrbitzToOther_Acc.ExactConditionList.Add(GeoComparer2);
                match_OrbitzToOther_Acc.ExactConditionList.Add(TelephoneComparer);
                match_OrbitzToOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_OrbitzToOther_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_OrbitzToOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_OrbitzToOther_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);

                match_OrbitzToOther_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_OrbitzToOther_Acc.ResultList, match_OrbitzToOther_Acc.GetMatchName());

                foreach (var result in match_OrbitzToOther_Acc.ResultList)
                {
                    var bEntity = BookingList.Where(bentity => bentity.HotelCode == result.HotelCode && bentity.HotelGroup == result.HotelGroup)
                        .First();

                    BookingList.Remove(bEntity);
                }
                Y_FileOutputer.DoOutput(BookingList, country.CountryName + "_未和系统其他酒店匹配上的Orbitz酒店");
            }

        }

        /// <summary>
        /// Booking 11237 vs other 2014-04-14
        /// </summary>
        public static void StartMatch20140414()
        {
            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            NameAddressAccComparer.SetTargetIsContinue(false);
            GeoComparer1.SetTargetIsContinue(false);
            GeoComparer2.SetTargetIsContinue(false);
            TelephoneComparer.SetTargetIsContinue(false);
            NameAddressHighSimComparer.SetTargetIsContinue(false);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            List<CountryEntity> CountryList = CountryData.GetCountryList();

            List<string> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\BookingId.txt");
            
            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";

                List<HotelEntity> OtherList = OtherData.GetData(country.CountryId, new List<int>() { 32,36,27 });
                List<HotelEntity> BookingList = BookingData.GetDataByCityId(country.CountryId, 0, BookingHotelList);
                //List<HotelEntity> OrbitzList = OrbitzData.GetData(country.CountryCode, null);
                //OtherList.AddRange(OrbitzList);

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_BookingToOther_精确匹配";
                MatchOutName = MatchName;
                leftNumber = BookingList.Count;
                rightNumber = OtherList.Count;

                MatchEntity match_OrbitzToOther_Acc = new MatchEntity(MatchName);
                match_OrbitzToOther_Acc.LeftTargetEntityList = BookingList;
                match_OrbitzToOther_Acc.RightToCompareEntityList = OtherList;
                match_OrbitzToOther_Acc.ResultList = new List<HotelEntity>();
                match_OrbitzToOther_Acc.ExactConditionList = new List<ICompareCondition>();

                match_OrbitzToOther_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_OrbitzToOther_Acc.ExactConditionList.Add(GeoComparer1);
                match_OrbitzToOther_Acc.ExactConditionList.Add(GeoComparer2);
                match_OrbitzToOther_Acc.ExactConditionList.Add(TelephoneComparer);
                match_OrbitzToOther_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_OrbitzToOther_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_OrbitzToOther_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_OrbitzToOther_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);

                match_OrbitzToOther_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_OrbitzToOther_Acc.ResultList, match_OrbitzToOther_Acc.GetMatchName());

                foreach (var result in match_OrbitzToOther_Acc.ResultList)
                {
                    var bEntity = BookingList.Where(bentity => bentity.HotelCode == result.HotelCode && bentity.HotelGroup == result.HotelGroup)
                        .First();

                    BookingList.Remove(bEntity);
                }
                Y_FileOutputer.DoOutput(BookingList, country.CountryName + "_未和系统其他酒店匹配上的Booking酒店");
            }

        }

        public static void StartMatch20141028()
        {
            List<string> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\Agoda10.txt");

            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            NameAddressAccComparer.SetTargetIsContinue(false);
            GeoComparer1.SetTargetIsContinue(false);
            GeoComparer2.SetTargetIsContinue(false);
            TelephoneComparer.SetTargetIsContinue(false);
            NameAddressHighSimComparer.SetTargetIsContinue(false);

            List<CountryEntity> CountryList = new List<CountryEntity>(); //CountryData.GetCountryListOrbitz();
            CountryList.Add(new CountryEntity() { CountryCode = "13", CountryEnName = "Czech", CountryName = "捷克", CountryId = 162 });
            CountryList.Add(new CountryEntity() { CountryCode = "38", CountryEnName = "Vietnam", CountryName = "越南", CountryId = 111 });
            CountryList.Add(new CountryEntity() { CountryCode = "81", CountryEnName = "U.S. VIRGIN ISLANDS", CountryName = "美属维尔京群岛", CountryId = 280 });
            CountryList.Add(new CountryEntity() { CountryCode = "401", CountryEnName = "Palestine", CountryName = "巴勒斯坦", CountryId = 205 });
            CountryList.Add(new CountryEntity() { CountryCode = "32", CountryEnName = "Northern Mariana Island", CountryName = "北马里亚纳群岛", CountryId = 262 });
            CountryList.Add(new CountryEntity() { CountryCode = "190", CountryEnName = "Laos", CountryName = "老挝", CountryId = 55 });
            CountryList.Add(new CountryEntity() { CountryCode = "us", CountryEnName = "U.S.A.", CountryName = "美国", CountryId = 66 });
            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";
                List<HotelEntity> AgodaList = AgodaData.GetDataByCityId(country.CountryId, 0, BookingHotelList);
                //List<HotelEntity> BookingList = BookingData.GetDataByCityId(country.CountryId, 0, BookingHotelList);
                List<HotelEntity> OtherList = OtherData.GetData(country.CountryId,new List<int>(){33}) ;

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_AtoOther_匹配";
                MatchOutName = MatchName;
                leftNumber = AgodaList.Count;
                rightNumber =  OtherList.Count;

                MatchEntity match_BtoA_Acc = new MatchEntity(MatchName);
                match_BtoA_Acc.LeftTargetEntityList = AgodaList;
                match_BtoA_Acc.RightToCompareEntityList = OtherList;
                match_BtoA_Acc.ResultList = new List<HotelEntity>();
                match_BtoA_Acc.ExactConditionList = new List<ICompareCondition>();

                match_BtoA_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer1);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer2);
                match_BtoA_Acc.ExactConditionList.Add(TelephoneComparer);
                match_BtoA_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_BtoA_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_BtoA_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_BtoA_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);


                match_BtoA_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_BtoA_Acc.ResultList, match_BtoA_Acc.GetMatchName());

                foreach (var result in match_BtoA_Acc.ResultList)
                {
                    var bEntity = AgodaList.Where(bentity => bentity.HotelCode == result.HotelCode && bentity.HotelGroup == result.HotelGroup)
                        .First();

                    AgodaList.Remove(bEntity);
                }
                Y_FileOutputer.DoOutput(AgodaList, country.CountryName + "_未和系统其他酒店匹配上的Agoda酒店");
            }
        }
        

        /// <summary>
        /// 查找因为没有电话无法生成的Agoda酒店（没有hotel）和Booking酒店匹配的结果
        /// </summary>
        public static void StartMatch20140825()
        {
            //Round thisRound = new Round("Booking2.5W Agoda2W酒店上线");

            //List<int> BookingHotelList = Y_FileReader.ReadIdFromFile(@"C:\BookingId.txt");
            List<string> AgodaHotelList = Y_FileReader.ReadIdFromFile(@"C:\arstulia.txt");

            ICompareCondition NameAddressAccComparer = new Impl_HotelNameAndAddressExactComparer();
            ICompareCondition TelephoneComparer = new Impl_TelephoneComparer();
            ICompareCondition GeoComparer1 = new Impl_LonLatComparer(1.0, 0.8);
            ICompareCondition GeoComparer2 = new Impl_LonLatComparer(2.0, 0.9);
            ICompareCondition NameAddressHighSimComparer = new Impl_NameAddressComparer(3, 0.9, 0.9);

            //5Km 酒店名称65%以上相似
            ICompareCondition SimNameAndGeoComparer = new Impl_SimGeoNameComparer(5.0, 0.67);
            //5Km 地址65%以上相似
            ICompareCondition SimAddressAndGeoComparer = new Impl_SimGeoAddressComparer(6.0, 0.67);

            NameAddressAccComparer.SetTargetIsContinue(false);
            GeoComparer1.SetTargetIsContinue(false);
            GeoComparer2.SetTargetIsContinue(false);
            TelephoneComparer.SetTargetIsContinue(false);
            NameAddressHighSimComparer.SetTargetIsContinue(false);

            List<CountryEntity> CountryList = CountryData.GetCountryListOrbitz();
            //CountryList.Add(new CountryEntity() { CountryCode = "13", CountryEnName = "Czech", CountryName="捷克", CountryId=162 });
            //CountryList.Add(new CountryEntity() { CountryCode = "38", CountryEnName = "Vietnam", CountryName = "越南", CountryId = 111 });
            //CountryList.Add(new CountryEntity() { CountryCode = "81", CountryEnName = "U.S. VIRGIN ISLANDS", CountryName = "美属维尔京群岛", CountryId = 280 });
            //CountryList.Add(new CountryEntity() { CountryCode = "401", CountryEnName = "Palestine", CountryName = "巴勒斯坦", CountryId = 205 });
            //CountryList.Add(new CountryEntity() { CountryCode = "32", CountryEnName = "Northern Mariana Island", CountryName = "北马里亚纳群岛", CountryId = 262 });
            //CountryList.Add(new CountryEntity() { CountryCode = "190", CountryEnName = "Laos", CountryName = "老挝", CountryId = 55 });

            CountryList.Add(new CountryEntity() { CountryCode = "CZ", CountryEnName = "Czech", CountryName="捷克", CountryId=162 });
            CountryList.Add(new CountryEntity() { CountryCode = "KR", CountryEnName = "South Korea", CountryName = "韩国", CountryId = 42 });
            CountryList.Add(new CountryEntity() { CountryCode = "LA", CountryEnName = "Laos", CountryName = "老挝", CountryId = 55 });
            CountryList.Add(new CountryEntity() { CountryCode = "LY", CountryEnName = "Libya", CountryName = "利比亚", CountryId = 60 });
            CountryList.Add(new CountryEntity() { CountryCode = "MD", CountryEnName = "Moldova", CountryName = "摩尔多瓦", CountryId = 182 });
            CountryList.Add(new CountryEntity() { CountryCode = "MP", CountryEnName = "Northern Mariana Island", CountryName = "北马里亚纳群岛", CountryId = 262 });
            CountryList.Add(new CountryEntity() { CountryCode = "PS", CountryEnName = "Palestine", CountryName = "巴勒斯坦", CountryId = 205 });
            CountryList.Add(new CountryEntity() { CountryCode = "SK", CountryEnName = "Slovakia", CountryName = "斯洛伐克", CountryId = 247 });
            CountryList.Add(new CountryEntity() { CountryCode = "TZ", CountryEnName = "Tanzania", CountryName = "坦桑尼亚", CountryId = 87 });
            CountryList.Add(new CountryEntity() { CountryCode = "VG", CountryEnName = "BRITISH VIRGIN ISLAN", CountryName = "英属维尔京群岛", CountryId = 282 });
            CountryList.Add(new CountryEntity() { CountryCode = "VI", CountryEnName = "U.S. VIRGIN ISLANDS", CountryName = "美属维尔京群岛", CountryId = 280 });
            CountryList.Add(new CountryEntity() { CountryCode = "VN", CountryEnName = "Vietnam", CountryName = "越南", CountryId = 111 });
            CountryList.Add(new CountryEntity() { CountryCode = "US", CountryEnName = "United States", CountryName = "美国", CountryId = 66 });

            foreach (var country in CountryList)
            {
                leftNumber = 0;
                rightNumber = 0;
                MatchOutName = "初始化数据";

                List<HotelEntity> BookingList = OtherData.GetData(country.CountryId, new List<int>() { 32 });
                List<HotelEntity> AgodaList = AgodaData.GetData(country.CountryCode, AgodaHotelList);

                //1111-------------------------------------------------------------------------------//
                string MatchName = country.CountryName + "_BtoA_精确匹配";
                MatchOutName = MatchName;
                leftNumber = AgodaList.Count;
                rightNumber =  BookingList.Count;

                MatchEntity match_BtoA_Acc = new MatchEntity(MatchName);
                match_BtoA_Acc.LeftTargetEntityList = AgodaList;
                match_BtoA_Acc.RightToCompareEntityList = BookingList;
                match_BtoA_Acc.ResultList = new List<HotelEntity>();
                match_BtoA_Acc.ExactConditionList = new List<ICompareCondition>();

                match_BtoA_Acc.ExactConditionList.Add(NameAddressAccComparer);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer1);
                match_BtoA_Acc.ExactConditionList.Add(GeoComparer2);
                match_BtoA_Acc.ExactConditionList.Add(TelephoneComparer);
                match_BtoA_Acc.ExactConditionList.Add(NameAddressHighSimComparer);

                match_BtoA_Acc.SimilarConditionList = new List<ICompareCondition>();
                match_BtoA_Acc.SimilarConditionList.Add(SimNameAndGeoComparer);
                match_BtoA_Acc.SimilarConditionList.Add(SimAddressAndGeoComparer);


                match_BtoA_Acc.DoMatch();
                Y_FileOutputer.DoOutput(match_BtoA_Acc.ResultList, match_BtoA_Acc.GetMatchName());
            }
        }
    }
}
